package com.example.fitnessservice.module.dao.bbsmapper;

import com.example.fitnessservice.module.pojo.*;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BbsMapper {
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "dynamicId", column = "dynamic_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "dynamicContentId", column = "dynamic_content_id"),
            @Result(property = "like", column = "like"),
            @Result(property = "reportId", column = "report_id"),
            @Result(property = "userDynamicContent",javaType = UserDynamicContent.class,  column = "dynamic_id", one = @One(select = "com.example.fitnessservice.module.dao.bbsmapper.BbsMapper.findByDynamicId"))
    })
    @Select("select * from user_dynamic")
    public List<UserDynamic> findDynamic();
    @Select("select * from user_dynamic_content where dynamic_id = #{dynamicId}")
    public UserDynamicContent findByDynamicId(int dynamicId);

    @Select("select * from user_info where user_id = #{userId}")
    public UserInfo findUserInfo(Integer userId);

    @Select("select * from user_dynamic_fans where user_id = #{userId}")
    public List<UserDynamicFans> findAllFans(Integer userId);

    @Select("select * from user_dynamic_attention where user_id = #{userId}")
    public List<UserDynamicAttention> findAllAttention(Integer userId);

    @Select("select count(*) from user_dynamic_fans where user_id = #{userId}")
    public int findFansNum(Integer userId);

    @Select("select count(*) from user_dynamic_attention where user_id = #{userId}")
    public int findAttentionNum(Integer userId);

    @Insert("insert into user_dynamic_attention(user_id,attention_id) values(#{userId},#{attentionId}) ")
    public int addAttention(UserDynamicAttention userDynamicAttention);

    @Insert("insert into user_dynamic_fans(user_id,fans_id) values(#{userId},#{fansId}) ")
    public int addFans(UserDynamicFans userDynamicFans);

    @Delete("delete from user_dynamic_attention where user_id = #{userId} and attention_id = #{attentionId}")
    public int deleteAttention(UserDynamicAttention userDynamicAttention);

    @Delete("delete from user_dynamic_fans where user_id = #{userId} and fans_id = #{fansId}")
    public int deleteFans(UserDynamicFans userDynamicFans);

    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "dynamicId", column = "dynamic_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "dynamicContentId", column = "dynamic_content_id"),
            @Result(property = "like", column = "like"),
            @Result(property = "reportId", column = "report_id"),
            @Result(property = "userDynamicContent",javaType = UserDynamicContent.class,  column = "dynamic_id", one = @One(select = "com.example.fitnessservice.module.dao.bbsmapper.BbsMapper.findByDynamicId"))
    })
    @Select("select * from user_dynamic where user_id = #{userId}")
    public List<UserDynamic> findDynamicByUserId(Integer userId);

    @Update("update user_dynamic set dynamic_like = dynamic_like + 1 where dynamic_id = #{dynamicId}")
    public int plusLike(Integer dynamicId);

    @Update("update user_dynamic set dynamic_like = dynamic_like - 1 where dynamic_id = #{dynamicId}")
    public int subtractLike(Integer dynamicId);

    @Select("select * from user_dynamic_sensitive_words")
    public List<UserDynamicSensitiveWord> findSensitiveWords();

    @Insert("insert into user_dynamic_comment (dynamic_id,comment_content) values (#{dynamicId},#{commentContent})")
    public int addDynamicComment(UserDynamicComment userDynamicComment);

    @Delete("delete from user_dynamic_comment where id = #{id}")
    public int deleteDynamicComment(UserDynamicComment userDynamicComment);

    @Select("select * from user_dynamic_comment where dynamic_id = #{dynamicId}")
    public List<UserDynamicComment> findDynamicComment(Integer dynamicId);

    @Select("select * from user_dynamic_report")
    public List<UserDynamicReport> findReportContent();

    @Update("update user_dynamic set report_id = #{reportId} where dynamic_id = #{dynamicId}")
    public int submitReport(Integer reportId, Integer dynamicId);

    @Insert("insert into user_dynamic_content (user_id,monicker,height,gender,birthday,city,industry,income,education,marriage,signature,harvest_address,phone,image) values(userId,monicker,height,gender,birthday,city,industry,income,education,marriage,signature,harvestAddress,phone,image)")
    public int addUserInfo(UserInfo userInfo);

    @Delete("delete from user_dynamic_comment where dynamic_id = #{dynamicId}")
    public int deleteDynamicCommentByDynamicId(Integer dynamicId);
    @Delete("delete from user_dynamic_content where dynamic_id = #{dynamicId}")
    public int deleteDynamicContent(Integer dynamicId);
    @Delete("delete from user_dynamic where dynamic_id = #{dynamicId}")
    public int deleteDynamic(Integer dynamicId);

    @Update("update user_dynamic_content set monicker = #{monicker},height = #{height},gender = #{gender},birthday = #{birthday},city = #{city},industry = #{monicker},income = #{income},education = #{education},marriage = #{monicker},signature = #{signature},harvest_address = #{harvestAddress},phone = #{phone},image = #{image} where user_id = #{userId}")
    public int updateUserInfo(UserInfo userInfo);

}
